﻿<script type="text/javascript">
    $(function () {
        getButton("sqlanswer");
    });

    function ui_sqlanswer_init_list(toolbar) {
        $("#ui_sqlanswer_dg").datagrid({       //初始化datagrid
            url: "ashx/rm_sqlanswer.ashx?action=search",
            striped: true, rownumbers: true, pagination: true, pageSize: 20,
            idField: 'id',
            sortName: 'submittime',
            sortOrder: 'desc',
            pageList: [20, 40, 60, 80, 100],
            frozenColumns: [[
                { field: 'ck', checkbox: true },
                {
                    field: 'questionTitle', title: '试题名称', width: 300, sortable: true,
                    formatter: function (value, row, index) {
                        value = $('<div>' + value + '</div>').text();
                        return value.length > 100 ? '<span title="' + value + '">' + value.substring(0, 100) + ' </span> ...' : value;
                    }
                }
            ]],
            columns: [[
                {
                    field: 'answer', title: '考生答案', width: 320, sortable: false,
                    formatter: function (value, row, index) {
                        //value = "******";
                        return value.length > 100 ? '<span title="'+value+'">' + value.substring(0, 100) + ' </span> ...' : value;
                    }
                },
                {
                    field: 'statusStr', title: '答题状态', width: 300, sortable: false,
                    formatter: function (value, row, index) {
                        value = $('<div>'+value+'</div>').text();
                        return value.length > 100 ? '<span title="' + value + '">' + value.substring(0, 100) + ' </span> ...' : value;
                    }
                },
                { field: 'point', title: '得分', width: 60, sortable: false },
                { field: 'submittime', title: '答题时间', width: 160, sortable: true },
                { field: 'username', title: '用户', width: 120, sortable: false }
            ]],
            toolbar: toolbar.length == 0 ? null : toolbar
            //toolbar: [{
            //    text: '添加',
            //    iconCls: 'icon-add',
            //    handler: function () { ui_sqlanswer_add(); }
            //}, {
            //    text: '修改',
            //    iconCls: 'icon-edit',
            //    handler: function () { ui_sqlanswer_edit(); }
            //}, '-', {
            //    text: '删除',
            //    iconCls: 'icon-remove',
            //    handler: function () { ui_sqlanswer_delete() }
            //}]
        });
    }
    function ui_sqlanswer_add() {
        $.show_warning("提示", "功能未实现！");
    }
    function ui_sqlanswer_edit() {
        $.show_warning("提示", "功能未实现！");
    }
    function ui_sqlanswer_delete() {
        var rows = $("#ui_sqlanswer_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要删除的记录");
            return;
        }
        $.messager.confirm('提示', '确定删除勾选的这' + rows.length + '条记录？', function (r) {
            if (r) {
                para = {};
                para.action = "delete";
                para.timespan = new Date().getTime();

                var ids = [];
                $.each(rows, function (i, row) {
                    ids.push(row.id);
                });
                para.ids = ids.join(',');
                $.ajax({
                    url: "ashx/rm_sqlanswer.ashx",
                    data: para,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        if (data.success) {
                            $.show_warning("提示", "删除成功！");
                            $("#ui_sqlanswer_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                        } else {
                            $.show_warning("提示", data.msg);
                        }
                    }
                });
            }
        });
    }

    function ui_sqlanswer_searchdata() {
        $("#ui_sqlanswer_dg").datagrid('load', {
            username: $('#ui_sqlanswer_search').find('[name=ui_sqlanswer_username]').val(),
            deptname: $('#ui_sqlanswer_search').find('[name=ui_sqlanswer_deptname]').val(),
            questionname: $('#ui_sqlanswer_search').find('[name=ui_sqlanswer_questionname]').val(),
            status: $('#ui_sqlanswer_search').find('[name=ui_sqlanswer_status]').val(),            
            answerdatestart: $('#ui_sqlanswer_answerdatestart').datetimebox('getValue'),
            answerdateend: $('#ui_sqlanswer_answerdateend').datetimebox('getValue')
        });
        $("#ui_sqlanswer_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_sqlanswer_layout').layout('collapse', 'east');    //隐藏
    }
    function ui_sqlanswer_cleardata() {
        $('#ui_sqlanswer_search input').val('');
        $('#ui_sqlanswer_search select').val('select');
        $('#ui_sqlanswer_answerdatestart').datetimebox('setValue', '');
        $('#ui_sqlanswer_answerdateend').datetimebox('setValue', '');
        $("#ui_sqlanswer_dg").datagrid('load', {});

        $("#ui_sqlanswer_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_sqlanswer_layout').layout('collapse', 'east');    //隐藏
    }
</script>
<div id="ui_sqlanswer_layout" class="easyui-layout" data-options="fit:true,border:false">    
    <div data-options="region:'center',border:false">
        <table id="ui_sqlanswer_dg" data-options="fit:true,border:false">
        </table>
    </div>
    <div data-options="region:'east',split:true,border:true,collapsed:true" title="多条件过滤"
        style="width: 280px;">
        <div id="ui_sqlanswer_search">
            <table class="tableForm" style="width: 100%; height: 100%; background: #F5F5F5;">
                <tr>
                    <th>姓名：
                    </th>
                    <td>
                        <input name="ui_sqlanswer_username" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>部门名称：
                    </th>
                    <td>
                        <input name="ui_sqlanswer_deptname" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>试题名称：
                    </th>
                    <td>
                        <input name="ui_sqlanswer_questionname" autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>是否正确：
                    </th>
                    <td>
                        <select name="ui_sqlanswer_status">
                            <option value="select">请选择</option>
                            <option value="1">正确</option>
                            <option value="2">错误</option>
                            <option value="3">语法错误</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>答题时间：
                    </th>
                    <td>
                        <input name="ui_sqlanswer_answerdatestart" id="ui_sqlanswer_answerdatestart" class="easyui-datetimebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <th>至：
                    </th>
                    <td>
                        <input name="ui_sqlanswer_answerdateend" id="ui_sqlanswer_answerdateend" class="easyui-datetimebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                            onclick="ui_sqlanswer_searchdata();">搜索</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                            onclick="ui_sqlanswer_cleardata();">清空条件</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
